package jvm.t1;

import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;

/**
 * Remarks:空间内存溢出
 * Class name :Demo1_8
 * Date :2023/2/8 22:32
 * Author:杨俊源
 */
public class Demo1_8 extends ClassLoader{

    public static void main(String[] args) {
        int j = 0;
        try {
            Demo1_8 test = new Demo1_8();
            for (int i = 0;i < 10000;i++,j++){
                ClassWriter classWriter = new ClassWriter(0);
                classWriter.visit(Opcodes.V1_8,Opcodes.ACC_PUBLIC,"Class" + i,null,"java/lang/Object",null);
                byte[] code = classWriter.toByteArray();
                test.defineClass("Class" + i,code,0,code.length);
            }
        }finally {
            System.out.println(j);
        }
    }
}
